Code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Package
{
public:
// constructor initiliazes data members
Package( const string &, const string &, const string &,
const string &, int, const string &, const string &, const string &,
const string &, int, double, double );
void setSenderName( const string & );
string getSenderName() const;
void setSenderAddress( const string & );
string getSenderAddress() const;
void setSenderCity( const string & );
string getSenderCity() const;
void setSenderState( const string & );
string getSenderState() const;
void setSenderZIP( int );
int getSenderZIP() const;
void setRecipientName( const string & );
string getRecipientName() const;
void setRecipientAddress( const string & );
string getRecipientAddress() const;
void setRecipientCity( const string & );
string getRecipientCity() const;
void setRecipientState( const string & );
string getRecipientState() const;
void setRecipientZIP( int );
int getRecipientZIP() const;
void setWeight( double );
double getWeight() const;
void setCostPerOunce( double );
double getCostPerOunce() const;
virtual double calculateCost() const;
private:
// data members to store sender and recipient's address information
string senderName;
string senderAddress;
string senderCity;
string senderState;
int senderZIP;
string recipientName;
string recipientAddress;
string recipientCity;
string recipientState;
int recipientZIP;
double weight; // weight of the package
double costPerOunce; // cost per ounce to ship the package
};
//-----------------------------------------------------------------------------------------------------------//
class OvernightPackage : public Package
{
public:
OvernightPackage( const string &, const string &, const string &, const string &, int,
const string &, const string &, const string &, const string &, int, double, double, double );
void setOvernightFeePerOunce( double );
double getOvernightFeePerOunce() const;
virtual double calculateCost() const;
private:
double overnightFeePerOunce; // fee per ounce for overnight delivery
}; // end class OvernightPackage
//-----------------------------------------------------------------------------------------------------------//
// OvernightPackage constructor
OvernightPackage::OvernightPackage( const string &sName, const string &sAddress, const string &sCity,
const string &sState, int sZIP, const string &rName, const string &rAddress, const string &rCity,
const string &rState, int rZIP, double w, double cost, double fee ) : Package( sName, sAddress, sCity,
sState, sZIP, rName, rAddress, rCity, rState, rZIP, w, cost )
.
..
...
//-----------------------------------------------------------------------------------------------------------//
class TwoDayPackage : public Package
{
public:
TwoDayPackage( const string &, const string &, const string &, const string &, int,
const string &, const string &, const string &, const string &, int, double, double, double );
void setFlatFee( double );
double getFlatFee() const;
virtual double calculateCost() const;
private:
double flatFee;
};
//-----------------------------------------------------------------------------------------------------------//
// TwoDayPackage constructor
TwoDayPackage::TwoDayPackage( const string &sName, const string &sAddress,
const string &sCity, const string &sState, int sZIP, const string &rName, const string &rAddress,
const string &rCity, const string &rState, int rZIP, double w, double cost, double fee )
: Package( sName, sAddress, sCity, sState, sZIP, rName, rAddress, rCity, rState, rZIP, w, cost )
.
..
...
//-----------------------------------------------------------------------------------------------------------//
// Package constructor initiliazes data members
Package::Package( const string &sName, const string &sAddress, const string &sCity, const string &sState,
int sZIP, const string &rName, const string &rAddress, const string &rCity, const string &rState, int rZIP,
double w, double cost ) : senderName( sName ), senderAddress( sAddress ), senderCity( sCity ),
senderState( sState ), senderZIP( sZIP ), recipientName( rName ), recipientAddress( rAddress ),
recipientCity( rCity ), recipientState( rState ), recipientZIP( rZIP )
.
..
...
//-----------------------------------------------------------------------------------------------------------//
int main()
{
//This is the test program
OvernightPackage NightDeliver("Micheal", "Dr Rajkumar Road", "Rajajinagar Stage II",
"Bangalore", 12345, "Mathan", "Manjunath Road", "Berhampur", "Orissa", 54321, 16.00, 1.00, .25 );
TwoDayPackage DayDeliver("Kamal", "Amravati Road", "Nagpur", "Maharashtra", 33333,
"Rajan", "Vijayawada Road", "Ansari Nagar", "New Delhi", 44444, 10.5, .65, 2.0 );
cout << fixed << setprecision(2);
cout << "Customers for overnight delivery\n";
cout << "\n";
cout << "The sender :\n" << NightDeliver.getSenderName()<< "\n";
cout << NightDeliver.getSenderAddress() << "\n";
cout << NightDeliver.getSenderCity() << " " << NightDeliver.getSenderState() << " "
<< NightDeliver.getSenderZIP() << "\n";
cout << "\n";
cout << "The recipient :\n" << NightDeliver.getRecipientName()<< "\n";
cout << NightDeliver.getRecipientAddress() << "\n";
cout << NightDeliver.getRecipientCity() << " " << NightDeliver.getRecipientState() << " "
<< NightDeliver.getRecipientZIP() << "\n";
cout << "The cost is $ " << NightDeliver.calculateCost() << "\n";
cout << "\n\n";
cout << "Customers for 2 days delivery\n";
cout << "\n";
cout << "The sender :\n" << DayDeliver.getSenderName()<< "\n";
cout << DayDeliver.getSenderAddress() << "\n";
cout << DayDeliver.getSenderCity() << " " << DayDeliver.getSenderState() << " "
<< DayDeliver.getSenderZIP() << "\n";
cout << "\n";
cout << "The recipient :\n" << DayDeliver.getRecipientName()<< "\n";
cout << DayDeliver.getRecipientAddress() << "\n";
cout << DayDeliver.getRecipientCity() << " " << DayDeliver.getRecipientState() << " "
<< DayDeliver.getRecipientZIP() << "\n";
cout << "The cost is $ " << DayDeliver.calculateCost() << "\n";
cout << "\n\n";
system ("pause");
return 0;
}